package com.flong.juc.charter1;

import lombok.Data;

/**
 * @Author:liangjl
 * @Date: 2020/7/4-21:15
 * @Eamil:jilongliang@sina.com
 * @Description:
 * 暂停 resume
 * 挂起 suspend 如果独占公共的同步对象，使其他线程无法访问公共同步对象
 */
public class MyTest8 {

    public static void main(String[] args) throws InterruptedException {
        MyTest8Thread t = new MyTest8Thread();
        t.start();
        Thread.sleep(1000);

        //暂停线程，废弃方法
        t.resume();

        System.out.println("A=" + System.currentTimeMillis() + ",i=" + t.getI());
        Thread.sleep(1000);

        System.out.println("A=" + System.currentTimeMillis() + ",i=" + t.getI());

        //恢复暂停运行线程
        t.resume();
        Thread.sleep(1000);

        //挂起线程
        t.suspend();

        System.out.println("B=" + System.currentTimeMillis() + ",i=" + t.getI());
        Thread.sleep(1000);

        System.out.println("B=" + System.currentTimeMillis() + ",i=" + t.getI());
    }

}

@Data
class MyTest8Thread extends Thread {
    private long i = 0;

    @Override
    public void run() {
        while (true) {
            i++;
        }
    }
}